Vectors and Array Programming

Table of Contents

1. Array Programming

1.1. Array Arithmetics

We can perform arithmetics directly on vectors, thanks to Odin built-ins. For example, addition or subtraction if the 2 arrays have same dimensions, as well as scalar multiplication and element-wise multiplication.

2. Advanced Features of Arrays

2.1. Array as Vector

When an array is declared with 4 or less elements, we can use .x, .y, .z, .w to indicate [0], [1], [2], [3]. And we can arbitrarily combine them together. .xyzw can also be replaced by .rgba

  pos := [4]f32 {1, 2, 3, 4}

  xy := pos.xy // [2]f32 {1, 2}
  rr := pos.rr // [2]f32 {1, 1}
  yw := pos.yw // [2]f32 {2, 4}

Date: 2026-07-18 Sat